package com.itqf.controller;

import com.itqf.execption.UserLoginExecption;
import com.itqf.pojo.User;
import com.itqf.servie.ExecuptionUserService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * projectName: springmvcgp8
 *
 * @author: 赵伟风
 * time: 2021/8/6 16:19
 * description:
 */
@RestController
@RequestMapping("user")
@CrossOrigin("*")
public class UserController  {

     @GetMapping(value = "login",produces = "application/json;charset=utf-8")
     public Object login(String username,String password) throws UserLoginExecption {


         Map<String,Object> data = new HashMap<>();


         ExecuptionUserService userService = new ExecuptionUserService();
         User user = userService.login(username, password);

         data.put("code",200);
         data.put("user", user);
//
//         //失败
//         data.put("code", 300);
//         data.put("message", "xxx");
//
//         UserService userService = new UserService();
//         Map<String, Object> map = userService.login(username, password);
//
//         int state = (int) map.get("state");
//
//         if (state != 4)
//         {
//
//             data.put("code", 300);
//
//             if (state == 1){
//                 data.put("message", "账号或密码null");
//             }else if(state == 2)
//             {
//                 data.put("message", "账号错误");
//             }else{
//                 data.put("message", "密码错误");
//             }
//
//         }else {
//             data.put("code", 200);
//             data.put("user", map.get("user"));
//         }


         return  data;
     }





}
